var $ = require('../../utils/Ajax.js');
var QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
Page({
  data: {
    Id: null,
    Unused: null,
    // 图片地址
    PaddingBottom: 110,
    PictureUrl: getApp().PictureUrl
  },

  onLoad: function (options) {
    var that = this;
    wx.setNavigationBarTitle({
      title: "未使用"
    })
    $.Ajax("api/x_order_info", "POST", {
      id: options.Id
    }, function (res) {
      if (res.d.order.order_type != 1){
        that.setData({
          PaddingBottom: 0
        })
      }
      that.setData({
        Id: options.Id,
        Unused: res.d.order
      })
    });

  },
  
  OrderRefund: function (e){
    var Title = e.target.dataset.title;
    var StartTime = e.target.dataset.starttime;
    var EndTime = e.target.dataset.endtime
    var Phone = e.target.dataset.phone;
    var Num = e.target.dataset.num;
    var Price = e.target.dataset.price;
    var Amount = e.target.dataset.amount;
    wx.navigateTo({
      url: '../Refund/Refund?Title=' + Title + "&StartTime=" + StartTime + '&EndTime=' + EndTime + "&Phone=" + Phone + "&Num=" + Num + "&Id=" + this.data.Id + "&Price=" + Price + "&Amount=" + Amount
    })
  },

  callPhone: function (e) {
    var phone = e.currentTarget.dataset.ph;
    wx.makePhoneCall({
      phoneNumber: phone
    })
  },

  // 点击位置导航
  SetOut: function (e) {
    var Address = e.currentTarget.dataset.address;
    wx.showModal({
      title: '位置导航',
      content: '你确定要打开前往 ' + Address + ' 的路线导航吗？',
      confirmText: "确定",
      cancelText: "取消",
      success: function (res) {
        if (res.confirm) {
          var wxMap = new QQMapWX({
            key: 'YQ6BZ-XJXKI-VSIGO-5ILBX-SLBK5-OVFHK'
          });
          // 商户所在位置经纬度
          wxMap.geocoder({
            address: Address,
            success: function (res) {
              wx.openLocation({
                latitude: res.result.location.lat,
                longitude: res.result.location.lng,
                name: Address,
                scale: 28
              })
            }
          });
        } else {
          return false;
        }
      }
    });
  }
});